/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.feature.payment.core.wxpay.model.pay;

import yhao.infra.common.util.CommonDateUtil;
import yhao.infra.common.util.MathUtil;
import yhao.infra.feature.payment.core.support.NotifyUrl;
import yhao.infra.feature.payment.core.wxpay.model.WxBasePostModel;

import java.util.Date;

/**
 * 微信支付封装对象
 *
 * @author yoara
 */
public class WxPayModel extends WxBasePostModel {
    //商品或支付单简要描述(32)
    protected String body;
    //商户订单号,商户系统内部的订单号,32个字符内、可包含字母
    protected String out_trade_no;
    //订单总金额(分),只能为整数，详见支付金额
    protected int total_fee;
    //8.8.8.8	APP和网页支付提交用户端ip，Native支付填调用微信支付API的机器IP。
    protected String spbill_create_ip;
    //超时时间
    protected String time_expire;
    //接收微信支付异步通知回调地址
    protected String notify_url;
    //notify_business_url，该字段仅用作区分回调，不是sign加密的一部分
    protected String notify_business_url;

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
        //清除该字段数据，防止传递
        this.notify_business_url = null;
    }

    public String getTime_expire() {
        return time_expire;
    }

    public String getBody() {
        return body;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public int getTotal_fee() {
        return total_fee;
    }

    public String getSpbill_create_ip() {
        return spbill_create_ip;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public WxPayModel(String out_trade_no,
                      String body, double price, Date empireTime,
                      String spbill_create_ip, NotifyUrl url) {
        this.out_trade_no = out_trade_no;
        this.body = body;
        this.total_fee = (int) MathUtil.doubleMul(price, 100);
        this.time_expire = CommonDateUtil.formatDateToString(empireTime, "yyyyMMddHHmmss");
        this.spbill_create_ip = spbill_create_ip;
        this.notify_business_url = url.getUrl();
    }

    public String getNotify_business_url() {
        return notify_business_url;
    }
}

